package com.DongBing.controller;

import java.util.Arrays;
import java.util.Map;

import com.DongBing.service.CategoryService;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.DongBing.entity.AttrGroupEntity;
import com.DongBing.service.AttrGroupService;
import com.DongBing.common.utils.PageUtils;
import com.DongBing.common.utils.R;



/**
 * 属性分组
 *
 * @author ¶­±ù
 * @email 861571118@QQ.com
 * @date 2022-05-16 15:56:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/product/attrgroup")
public class AttrGroupController {

    private final AttrGroupService attrGroupService;

    private final CategoryService categoryService;

    /**
     * 列表
     */
    @GetMapping("/list/{cateLogId}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable("cateLogId") String cateLogId){
        PageUtils page = attrGroupService.queryPage(params,cateLogId);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    public R info(@PathVariable("attrGroupId") Long attrGroupId){
		val attrGroup = attrGroupService.getById(attrGroupId);
		val path = categoryService.findPath(attrGroup.getCatelogId());
		attrGroup.setPath(path);
        return R.ok().put("attrGroup", attrGroup);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.save(attrGroup);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateById(attrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds){
		attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return R.ok();
    }

}
